package design.pattern.Lu11DecoratorPattern;

/**
 * @program JavaBase
 * @description: 装饰器模式
 *  可以对任意类进行装饰
 * @author: zhanglu
 * @create: 2020-04-08 09:46:00
 */
public class DecoratorPattern02 {

    public static void main(String[] args) {

        FouthGradeSchoolReport02 fg = new FouthGradeSchoolReport02();

        //一次装饰
        fg = new ReportDecorator02(fg);

        //二次装饰
        fg = new SignDecorator02(fg);

        fg.report();
        fg.sign("zhangsan");

    }

}


class FouthGradeSchoolReport02{

    public void report() {
        System.out.println("这是一份成绩单");
    }

    public void sign(String name) {
        System.out.println("签名：" + name);
    }
}

abstract class Decorator02 extends FouthGradeSchoolReport02{

    private FouthGradeSchoolReport02 sr;

    public Decorator02(FouthGradeSchoolReport02 sr){
        this.sr = sr;
    }

    @Override
    public void report() {
        this.sr.report();
    }

    @Override
    public void sign(String name) {
        this.sr.sign(name);
    }
}

class ReportDecorator02 extends Decorator02{

    public ReportDecorator02(FouthGradeSchoolReport02 sr) {
        super(sr);
    }

    @Override
    public void report() {
        System.out.println("解说成绩单");
        super.report();
    }

}

class SignDecorator02 extends Decorator02{

    public SignDecorator02(FouthGradeSchoolReport02 sr) {
        super(sr);
    }

    @Override
    public void report() {
        System.out.println("不解说成绩单");
        super.report();
    }

    @Override
    public void sign(String name) {
        System.out.println("解说签名");
        super.sign(name);
    }
}



